package servlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.ArrayList;

import bean.User;
import dao.UserManagerDaoImpl;

public class showallUser extends HttpServlet{
	private static final long serialVersionUID = 1L;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		List<User> userlist = new ArrayList<User>();
		
		UserManagerDaoImpl userdao = new  UserManagerDaoImpl();
		userlist = userdao.getallUser();
		
		PrintWriter out = response.getWriter();
		StringBuffer sb = new StringBuffer();
		
		for(int i=0;i<userlist.size();i++) {
			sb.append("<tr class=\"scrolltype\" onclick=\"getinfo(this)\"><td class=\"first\">"+(i+1)+"</td><td>"+userlist.get(i).getUser_id()+"</td><td>"+userlist.get(i).getPassword()+"</td><td>"+userlist.get(i).isAdmin()+"</td></tr>");
		}
		
		String result = sb.toString();
		out.write(result);
		out.close();
		//request.setAttribute("userlist", userlist);
		//request.getRequestDispatcher("userManage.jsp").forward(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
}
